 * Menus.c
 *
 * Created: 2012-06-24 18:49:11
 *  Author: Sebastian_2
  

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <util/delay.h>
#include "Menu.h"
#include "Globals.h"
#include "misc.h"
#include "Menus.h"
#include "fonts/fonts.h"
#include "drivers/SSD1289.h"
#include "drivers/RGB565.h"

void Menu_Main_Enter() {
	CurrMenuItem = &Menu_Main;
	mPlayerGoBackToMain = 1;
	SSD1289_Clear();
	drawInfoBar();
	
	point p = {19, 56};
	ShowRGB565("/ico/mp3.565", &p);
	p.x = 94;
	ShowRGB565("/ico/radio.565", &p);
	p.x = 169;
	ShowRGB565("/ico/calendar.565", &p);
	p.x = 244;
	ShowRGB565("/ico/photo.565", &p);
	p.x = 19; p.y = 148;
	ShowRGB565("/ico/timer.565", &p);
	p.x = 94;
	ShowRGB565("/ico/recipes.565", &p);
	p.x = 169;
	ShowRGB565("/ico/calc.565", &p);
	p.x = 244;
	ShowRGB565("/ico/conf.565", &p);
}

// mp3
void Menu_MP3_Enter() {
	CurrMenuItem = &Menu_MP3;
	point p = {72, 48};
	point p2 = {245, 122};
	gColour = SUBMENU_BACKGROUND;
	SSD1289_DrawRect(&p, &p2);
	drawFrame(&p, &p2);
	gColour = FONT_COLOUR;
	p = (point){77, 54};
	SSD1289_PrintString("Odtwarzacz", &p, &tahoma20ptFontInfo);
	p = (point){72, 84};
	drawXSeparator(&p, 245, SEPARATOR);
	p = (point){77, 90};
	SSD1289_PrintString("Wykonawcy", &p, &tahoma20ptFontInfo);
}

void Menu_MP3_BackToMain() {
	CurrMenuItem = &Menu_Main;
	point p = {72, 48};
	point p2 = {246, 123};
	gColour = BACKGROUND;
	SSD1289_DrawRect(&p, &p2);
	p = (point){94, 56};
	ShowRGB565("/ico/radio.565", &p);
	p.x = 169;
	ShowRGB565("/ico/calendar.565", &p);
}

// artists
void Menu_Artists_Enter() {
	mArtistsCurrentPage = 0;
	Menu_Artists_Refresh();
}

void Menu_Artists_Refresh() {
	CurrMenuItem = &Menu_Artists;
	SSD1289_ClearOmitBar();
	
	FIL file;
	char tmp[50];
	char *ptr;
	point p = {10, 28};
	
	f_open(&file, "/music/IDX", FA_READ | FA_OPEN_EXISTING);
	// first go to wanted entry
	for(uint8_t i = 0; i < mArtistsCurrentPage*ITEMS_ON_PAGE; i++) {
		f_gets(tmp, sizeof(tmp), &file);
	}
	// now scan it and write it to global variable 
	uint8_t counter = 0;
	for(uint8_t i = 0; i < ITEMS_ON_PAGE; i++) {
		if(f_gets(tmp, sizeof(tmp), &file) == tmp) {
			char separator = 0x03;
			ptr = strtok(tmp, &separator);
			
			SSD1289_PrintString(ptr, &p, &tahoma20ptFontInfo);
			p = IncY(&p, 30); p.x = 0;
			drawXSeparator(&p, SSD1289_MaxX, SEPARATOR2);
			p = IncY(&p, 6); p.x = 10;
			
			ptr = strtok(NULL, "\n");
			strcpy(mArtistsDirList[i], ptr);
			counter++;
		}				
	}
	if(counter == 0) { // no lines were read = end of file
		mArtistsCurrentPage--;
		Menu_Artists_Refresh();
	}
}

void Menu_Artists_Row1() {
	mArtistsCurrentDir = 0;
	Menu_Songs_Refresh();
}

void Menu_Artists_Row2() {
	mArtistsCurrentDir = 1;
	Menu_Songs_Refresh();
}

void Menu_Artists_Row3() {
	mArtistsCurrentDir = 2;
	Menu_Songs_Refresh();
}

void Menu_Artists_Row4() {
	mArtistsCurrentDir = 3;
	Menu_Songs_Refresh();
}

void Menu_Artists_Row5() {
	mArtistsCurrentDir = 4;
	Menu_Songs_Refresh();
}

void Menu_Artists_Row6() {
	mArtistsCurrentDir = 5;
	Menu_Songs_Refresh();
}

// player
void Menu_Player_Enter() {
	if(gStatus & PLAYER_SSELECTED) {
		Menu_Player_Refresh();
	} else {
		SSD1289_ClearOmitBar();
		point p = {20, 40};
		SSD1289_PrintString("Nie wybrano utworu", &p, &tahoma20ptFontInfo);
		_delay_ms(200);
		Menu_Main_Enter();
	}
}

void Menu_Player_Refresh() {
	FIL file;
	FRESULT res;
	char tmp[100];
	point p;
	uint8_t pos;
	char *ptr;
	
	sprintf(tmp, "/music/%s/CNT", mArtistsDirList[mArtistsCurrentDir]);
	res = f_open(&file, tmp, FA_READ | FA_OPEN_EXISTING);
	f_gets(tmp, sizeof(tmp), &file);
	f_close(&file);
	sscanf(tmp, "%d", (int*)&mSongsMaxItems);
	pos = mSongsCurrentPage*ITEMS_ON_PAGE + mSongsSelectedRow;
	if(pos > mSongsMaxItems-1)
		return;
	if(CurrMenuItem != &Menu_Player) {
		SSD1289_ClearOmitBar();
		p = (point){7, 169};
		ShowRGB565("/ico/prev.565", &p);
		p = IncX(&p, 63);
		ShowRGB565("/ico/play.565", &p);
		p = IncX(&p, 63);
		ShowRGB565("/ico/stop.565", &p);
		p = IncX(&p, 63);
		ShowRGB565("/ico/repeat.565", &p);
		p = IncX(&p, 63);
		ShowRGB565("/ico/next.565", &p);
	} else {
		p = (point){0, 20};
		point p2 = {SSD1289_MaxX, 169};
		gColour = BACKGROUND;
		SSD1289_DrawRect(&p, &p2);
	}
	
	CurrMenuItem = &Menu_Player;
	
	sprintf(tmp, "/music/%s/IDX", mArtistsDirList[mArtistsCurrentDir]);
	res = f_open(&file, tmp, FA_READ | FA_OPEN_EXISTING);
	CheckRes();
	
	for(uint8_t i = 0; i < pos; i++) {
		f_gets(tmp, sizeof(tmp), &file);
	}
	if(f_gets(tmp, sizeof(tmp), &file) == tmp) {
		char separator = 0x03;
		uint16_t len;
		
		ptr = strtok(tmp, &separator);
		len = TextLength(ptr, &tahoma20ptFontInfo);
		p = (point){(SSD1289_MaxX-len)/2, 45};
		gColour = FONT_COLOUR;
		SSD1289_PrintString(ptr, &p, &tahoma20ptFontInfo);
		
		ptr = strtok(NULL, &separator);
		len = TextLength(ptr, &tahoma20ptFontInfo);
		p = (point){(SSD1289_MaxX-len)/2, 85};
		SSD1289_PrintString(ptr, &p, &tahoma20ptFontInfo);
		gStatus |= PLAYER_SSELECTED;
	}
}

void Menu_Player_Previous() {
	if(mSongsSelectedRow >= 1) {
		mSongsSelectedRow--;
		Menu_Player_Refresh();
	} else if(mSongsSelectedRow == 0 && mSongsCurrentPage >= 1) {
		mSongsCurrentPage--;
		mSongsSelectedRow = ITEMS_ON_PAGE-1;
		Menu_Player_Refresh();
	}
}

void Menu_Player_Next() {
	uint8_t pos = mSongsCurrentPage*ITEMS_ON_PAGE + mSongsSelectedRow;
	if(pos >= mSongsMaxItems-1)
		return;
	if(mSongsSelectedRow < ITEMS_ON_PAGE-1) {
		mSongsSelectedRow++;
		Menu_Player_Refresh();
	} else {
		mSongsSelectedRow = 0;
		mSongsCurrentPage++;
		Menu_Player_Refresh();
	}
}

void Menu_Player_PlayPause() {
	point p = {70, 169};
	
	if(gStatus & PLAYER_STOP) {
		gStatus &= ~PLAYER_STOP;
		gStatus |= PLAYER_PLAY;
		ShowRGB565("/ico/pause.565", &p);
	} else if(gStatus & PLAYER_PLAY) {
		gStatus &= ~PLAYER_PLAY;
		gStatus |= PLAYER_PAUSE;
		point p = {70, 169};
		ShowRGB565("/ico/pause.565", &p);
	} else if(gStatus & PLAYER_PAUSE) {
		gStatus &= ~PLAYER_PAUSE;
		gStatus |= PLAYER_PLAY;
		point p = {70, 169};
		ShowRGB565("/ico/play.565", &p);
	}
}

void Menu_Player_Stop() {
	point p = {70, 169};
	if(gStatus & PLAYER_PLAY) {
		gStatus &= ~PLAYER_PLAY;
		ShowRGB565("/ico/play.565", &p);
	} else if(gStatus & PLAYER_PAUSE) {
		gStatus &= ~PLAYER_PAUSE;
	}
	gStatus |= PLAYER_STOP;
	gStatus &= ~PLAYER_SSELECTED;
}

void Menu_Player_RepeatToggle() {
	point p = {196, 169};
	if(gStatus & PLAYER_REPEAT) {
		gStatus &= ~PLAYER_REPEAT;
		ShowRGB565("/ico/repeat.565", &p);
	} else {
		gStatus |= PLAYER_REPEAT;
		ShowRGB565("/ico/repeat2.565", &p);
	}
}

// songs
void Menu_Songs_Enter() {
	mSongsCurrentPage = 0;
	Menu_Songs_Refresh();
}

void Menu_Songs_Refresh() {
	CurrMenuItem = &Menu_Songs;
	SSD1289_ClearOmitBar();
	
	FIL file;
	FRESULT res;
	char tmp[100];
	point p = {10, 28};
		
	sprintf(tmp, "/music/%s/IDX", mArtistsDirList[mArtistsCurrentDir]);
	res = f_open(&file, tmp, FA_READ | FA_OPEN_EXISTING);
	CheckRes();
	for(uint8_t i = 0; i < mSongsCurrentPage*ITEMS_ON_PAGE; i++) {
		f_gets(tmp, sizeof(tmp), &file);
	}
	
	uint8_t counter = 0;
	for(uint8_t i = 0; i < ITEMS_ON_PAGE; i++) {
		if(f_gets(tmp, sizeof(tmp), &file) == tmp) {
			char separator = 0x03;
			char *ptr;
			ptr = strtok(tmp, &separator);
			ptr = strtok(NULL, &separator);
			
			SSD1289_PrintString(ptr, &p, &tahoma20ptFontInfo);
			p = IncY(&p, 30); p.x = 0;
			drawXSeparator(&p, SSD1289_MaxX, SEPARATOR2);
			p = IncY(&p, 6); p.x = 10;
			counter++;
		}
	}
	if(counter == 0) { // no lines were read = end of file
		mSongsCurrentPage--;
		Menu_Songs_Refresh();
	}
}

void Menu_Songs_Row1() {
	mSongsSelectedRow = 0;
	mPlayerGoBackToMain = 0;
	Menu_Player_Refresh();
}

void Menu_Songs_Row2() {
	mSongsSelectedRow = 1;
	mPlayerGoBackToMain = 0;
	Menu_Player_Refresh();
}

void Menu_Songs_Row3() {
	mSongsSelectedRow = 2;
	mPlayerGoBackToMain = 0;
	Menu_Player_Refresh();
}

void Menu_Songs_Row4() {
	mSongsSelectedRow = 3;
	mPlayerGoBackToMain = 0;
	Menu_Player_Refresh();
}

void Menu_Songs_Row5() {
	mSongsSelectedRow = 4;
	mPlayerGoBackToMain = 0;
	Menu_Player_Refresh();
}

void Menu_Songs_Row6() {
	mSongsSelectedRow = 5;
	mPlayerGoBackToMain = 0;
	Menu_Player_Refresh();
}

// radio
void Menu_Radio_Enter() {
	CurrMenuItem = &Menu_Radio;
	point p = {147, 48};
	point p2 = {245, 122};
	gColour = SUBMENU_BACKGROUND;
	SSD1289_DrawRect(&p, &p2);
	drawFrame(&p, &p2);
	gColour = FONT_COLOUR;
	p = (point){152, 54};
	SSD1289_PrintString("Stacje", &p, &tahoma20ptFontInfo);
	p = (point){147, 84};
	drawXSeparator(&p, 245, SEPARATOR);
	p = (point){152, 90};
	SSD1289_PrintString("Wylacz", &p, &tahoma20ptFontInfo);
}

void Menu_Radio_BackToMain() {
	CurrMenuItem = &Menu_Main;
	point p = {147, 48};
	point p2 = {246, 123};
	gColour = BACKGROUND;
	SSD1289_DrawRect(&p, &p2);
	p = (point){169, 56};
	ShowRGB565("/ico/calendar.565", &p);
}

void Menu_Radio_TurnOff() {
	// do some I2C magic	
}

void Menu_RStations_Enter() {
	mRStationsCurrentPage = 0;
	Menu_RStations_Refresh();
}

void Menu_RStations_Refresh() {
	CurrMenuItem = &Menu_RStations;
	
	FIL file;
	FRESULT res;
	char tmp[35];
	uint8_t pos;
	point p = {10, 28};
	
	pos = mRStationsCurrentPage*ITEMS_ON_PAGE + mRStationsSelectedRow;
	res = f_open(&file, "/radio", FA_READ | FA_OPEN_EXISTING);
	CheckRes();
	f_gets(tmp, sizeof(tmp), &file);
	sscanf(tmp, "%u", (uint16_t*)&mRStationsMaxItems);
	
	if(pos >= mRStationsMaxItems-1)
		return;
	
	for(uint8_t i = 0; i < mRStationsCurrentPage*ITEMS_ON_PAGE; i++) {
		f_gets(tmp, sizeof(tmp), &file);
	}
	
	SSD1289_ClearOmitBar();
	for(uint8_t i = 0; i < ITEMS_ON_PAGE; i++) {
		if(f_gets(tmp, sizeof(tmp), &file) == tmp) {
			char separator = 0x03;
			char *ptr;
			
			ptr = strtok(tmp, &separator);
			SSD1289_PrintString(ptr, &p, &tahoma20ptFontInfo);
			p = IncY(&p, 30); p.x = 0;
			drawXSeparator(&p, SSD1289_MaxX, SEPARATOR2);
			p = IncY(&p, 6); p.x = 10;
		}
	}
	f_close(&file);
}

void Menu_RStations_Row1() {
	mRStationsSelectedRow = 0;
	Menu_RStations_Refresh();
}

void Menu_RStations_Row2() {
	mRStationsSelectedRow = 1;
	Menu_RStations_Refresh();
}

void Menu_RStations_Row3() {
	mRStationsSelectedRow = 2;
	Menu_RStations_Refresh();
}

void Menu_RStations_Row4() {
	mRStationsSelectedRow = 3;
	Menu_RStations_Refresh();
}

void Menu_RStations_Row5() {
	mRStationsSelectedRow = 4;
	Menu_RStations_Refresh();
}

void Menu_RStations_Row6() {
	mRStationsSelectedRow = 5;
	Menu_RStations_Refresh();
}

// calendar
void Menu_Calendar_Enter() {
	mCalendarMonthToDisplay = gRTC.month;
	Menu_Calendar_Refresh();
}

void Menu_Calendar_Refresh() {
	CurrMenuItem = &Menu_Calendar;
	// calculate first day of the month using Zeller's formula
	uint8_t month;
	uint16_t year = gRTC.year;
	if(mCalendarMonthToDisplay >= 3) {
		month = mCalendarMonthToDisplay;
	 } else {
		month = mCalendarMonthToDisplay + 12;
		year--;
	 }		
	
	uint8_t k = year%100;
	uint8_t j = year/100;
	volatile uint16_t day = 1 + 13*(month+1)/5;
	day += k + (k>>2);
	day += (j>>2) + 5*j;
	day %= 7;
	// 0 = Saturday, 1 = Sunday, 2 = Monday, ... - need to change that
	if(day == 0 || day == 1)
		day += 6;
	else
		day--;
	
	// calculate amount of days in the month
	uint8_t days = 0;
	uint16_t year_full = gRTC.year + 2000;
	uint8_t leapYear;
	if(year_full%400 == 0 || year_full%4 == 0)
		leapYear = 1;
	else
		leapYear = 0;
	if(mCalendarMonthToDisplay == 1 || mCalendarMonthToDisplay == 3 || mCalendarMonthToDisplay == 5 || mCalendarMonthToDisplay == 7 || mCalendarMonthToDisplay == 8 || mCalendarMonthToDisplay == 10 || mCalendarMonthToDisplay == 12)
		days = 31;
	else if(mCalendarMonthToDisplay == 4 || mCalendarMonthToDisplay == 6 || mCalendarMonthToDisplay == 9 || mCalendarMonthToDisplay == 11)
		days = 30;
	else if(mCalendarMonthToDisplay == 2 && leapYear == 1)
		days = 29;
	else if(mCalendarMonthToDisplay == 2 && leapYear == 0)
		days = 28;
	// now print entire month on the screen
	char month_str[20];
	switch(mCalendarMonthToDisplay) {
		case 1:
		sprintf(month_str, "Styczen  %u", year_full);
		break;
		
		case 2:
		sprintf(month_str, "Luty  %u", year_full);
		break;
		
		case 3:
		sprintf(month_str, "Marzec  %u", year_full);
		break;
		
		case 4:
		sprintf(month_str, "Kwiecien  %u", year_full);
		break;
		
		case 5:
		sprintf(month_str, "Maj  %u", year_full);
		break;
		
		case 6:
		sprintf(month_str, "Czerwiec  %u", year_full);
		break;
		
		case 7:
		sprintf(month_str, "Lipiec  %u", year_full);
		break;
		
		case 8:
		sprintf(month_str, "Sierpien  %u", year_full);
		break;
		
		case 9:
		sprintf(month_str, "Wrzesien  %u", year_full);
		break;
		
		case 10:
		sprintf(month_str, "Pazdziernik  %u", year_full);
		break;
		
		case 11:
		sprintf(month_str, "Listopad  %u", year_full);
		break;
		
		case 12:
		sprintf(month_str, "Grudzien  %u", year_full);
		break;
	}
	uint16_t len = TextLength(month_str, &tahoma12ptFontInfo);
	point p = {(SSD1289_MaxX-len)>>1, 2};
	SSD1289_Clear();
	SSD1289_PrintString(month_str, &p, &tahoma12ptFontInfo);
	p.y = 24;
	
	uint8_t column = day-1;	
	for(uint8_t i = 0; i < days; i++) {
		char tmp[3];
		point p2;
		sprintf(tmp, "%d", i+1);
		uint16_t len = TextLength(tmp, &centuryGothic20ptFontInfo);
		p.x = 2 + column*47;
		p.x += (36-len) >> 1; // (x >> 1) == x/2
		if(i+1 == gRTC.date && mCalendarMonthToDisplay == gRTC.month) {
			gColour = CALENDAR_FONT_COLOUR;
			p2 = SSD1289_PrintString(tmp, &p, &centuryGothic20ptFontInfo);
			gColour = FONT_COLOUR;
		} else if(p.x >= 210){ // weekend
			gColour = CALENDAR_WEEKEND;
			p2 = SSD1289_PrintString(tmp, &p, &centuryGothic20ptFontInfo);
			gColour = FONT_COLOUR;
		} else {			
			p2 = SSD1289_PrintString(tmp, &p, &centuryGothic20ptFontInfo);
		}		
		if(p2.x >= 280) {
			p = IncY(&p, 38);
			column = 0;			
		} else {
			if(column <= 6) {
				column++;
			} else {
				column = 0;
			}				
		}
	}
	// draw separators
	// horizontal goes first
	p = (point){0, 50};
	for(uint8_t i = 0; i < 5; i++) {
		drawXSeparator(&p, SSD1289_MaxX, SEPARATOR3);
		p = IncY(&p, 39);
	}
	// and now vertical
	p = (point){45, 24};
	for(uint8_t i = 0; i < 6; i++) {
		drawYSeparator(&p, SSD1289_MaxY, SEPARATOR3);
		p = IncX(&p, 47);
	}
}

// keyboard
void Menu_Keyboard_Enter() {
	mKeyboardDisplay = UPPERCASE;
	Menu_Keyboard_Refresh();
}

void Menu_Keyboard_Refresh() {
	char buffer[100];
	
	SSD1289_ClearOmitBar();
}

void InitAllMenus(){
	// main menu
	TI_Main[0].Start = (point){19, 56};
	TI_Main[0].End = (point){75, 112};
	TI_Main[0].TouchFunc = &Menu_MP3_Enter;
	TI_Main[1].Start = (point){94, 56};
	TI_Main[1].End = (point){150, 112};
	TI_Main[1].TouchFunc = &Menu_Radio_Enter;
	TI_Main[2].Start = (point){169, 56};
	TI_Main[2].End = (point){225, 112};
	TI_Main[2].TouchFunc = &Menu_Calendar_Enter;
	
	// mp3 menu
	TI_MP3[0].Start = (point){19, 56};
	TI_MP3[0].End = (point){75, 112};
	TI_MP3[0].TouchFunc = &Menu_MP3_BackToMain;
	TI_MP3[1].Start = (point){72, 48};
	TI_MP3[1].End = (point){245, 84};
	TI_MP3[1].TouchFunc = &Menu_Player_Enter;
	TI_MP3[2].Start = (point){72, 90};
	TI_MP3[2].End = (point){245, 116};
	TI_MP3[2].TouchFunc = &Menu_Artists_Enter;
	
	// player menu
	TI_Player[0].Start = (point){7, 169};
	TI_Player[0].End = (point){63, 225};
	TI_Player[0].TouchFunc = &Menu_Player_Previous;
	TI_Player[1].Start = (point){70, 169};
	TI_Player[1].End = (point){126, 225};
	TI_Player[1].TouchFunc = &Menu_Player_PlayPause;
	TI_Player[2].Start = (point){133, 169};
	TI_Player[2].End = (point){189, 225};
	TI_Player[2].TouchFunc = &Menu_Player_Stop;
	TI_Player[3].Start = (point){196, 169};
	TI_Player[3].End = (point){252, 225};
	TI_Player[3].TouchFunc = &Menu_Player_RepeatToggle;
	TI_Player[4].Start = (point){259, 169};
	TI_Player[4].End = (point){315, 225};
	TI_Player[4].TouchFunc = &Menu_Player_Next;
	
	// artists menu
	TI_Artists[0].Start = (point){10, 28};
	TI_Artists[0].End = (point){SSD1289_MaxX, 58};
	TI_Artists[0].TouchFunc = &Menu_Artists_Row1;
	TI_Artists[1].Start = (point){10, 64};
	TI_Artists[1].End = (point){SSD1289_MaxX, 94};
	TI_Artists[1].TouchFunc = &Menu_Artists_Row2;
	TI_Artists[2].Start = (point){10, 100};
	TI_Artists[2].End = (point){SSD1289_MaxX, 130};
	TI_Artists[2].TouchFunc = &Menu_Artists_Row3;
	TI_Artists[3].Start = (point){10, 136};
	TI_Artists[3].End = (point){SSD1289_MaxX, 166};
	TI_Artists[3].TouchFunc = &Menu_Artists_Row4;
	TI_Artists[4].Start = (point){10, 172};
	TI_Artists[4].End = (point){SSD1289_MaxX, 202};
	TI_Artists[4].TouchFunc = &Menu_Artists_Row5;
	TI_Artists[5].Start = (point){10, 208};
	TI_Artists[5].End = (point){SSD1289_MaxX, 238};
	TI_Artists[5].TouchFunc = &Menu_Artists_Row6;
	
	// songs menu
	TI_Songs[0].Start = (point){10, 28};
	TI_Songs[0].End = (point){SSD1289_MaxX, 58};
	TI_Songs[0].TouchFunc = &Menu_Songs_Row1;
	TI_Songs[1].Start = (point){10, 64};
	TI_Songs[1].End = (point){SSD1289_MaxX, 94};
	TI_Songs[1].TouchFunc = &Menu_Songs_Row2;
	TI_Songs[2].Start = (point){10, 100};
	TI_Songs[2].End = (point){SSD1289_MaxX, 130};
	TI_Songs[2].TouchFunc = &Menu_Songs_Row3;
	TI_Songs[3].Start = (point){10, 136};
	TI_Songs[3].End = (point){SSD1289_MaxX, 166};
	TI_Songs[3].TouchFunc = &Menu_Songs_Row4;
	TI_Songs[4].Start = (point){10, 172};
	TI_Songs[4].End = (point){SSD1289_MaxX, 202};
	TI_Songs[4].TouchFunc = &Menu_Songs_Row5;
	TI_Songs[5].Start = (point){10, 208};
	TI_Songs[5].End = (point){SSD1289_MaxX, 238};
	TI_Songs[5].TouchFunc = &Menu_Songs_Row6;
	
	// radio
	TI_Radio[0].Start = (point){94, 56};
	TI_Radio[0].End = (point){150, 112};
	TI_Radio[0].TouchFunc = &Menu_Radio_BackToMain;
	TI_Radio[1].Start = (point){72, 48};
	TI_Radio[1].End = (point){245, 84};
	TI_Radio[1].TouchFunc = &Menu_RStations_Enter;
	TI_Radio[2].Start = (point){72, 90};
	TI_Radio[2].End = (point){245, 116};
	TI_Radio[2].TouchFunc = &Menu_Radio_TurnOff;
	
	TI_RStations[0].Start = (point){10, 28};
	TI_RStations[0].End = (point){SSD1289_MaxX, 58};
	TI_RStations[0].TouchFunc = &Menu_RStations_Row1;
	TI_RStations[1].Start = (point){10, 64};
	TI_RStations[1].End = (point){SSD1289_MaxX, 94};
	TI_RStations[1].TouchFunc = &Menu_RStations_Row2;
	TI_RStations[2].Start = (point){10, 100};
	TI_RStations[2].End = (point){SSD1289_MaxX, 130};
	TI_RStations[2].TouchFunc = &Menu_RStations_Row3;
	TI_RStations[3].Start = (point){10, 136};
	TI_RStations[3].End = (point){SSD1289_MaxX, 166};
	TI_RStations[3].TouchFunc = &Menu_RStations_Row4;
	TI_RStations[4].Start = (point){10, 172};
	TI_RStations[4].End = (point){SSD1289_MaxX, 202};
	TI_RStations[4].TouchFunc = &Menu_RStations_Row5;
	TI_RStations[5].Start = (point){10, 208};
	TI_RStations[5].End = (point){SSD1289_MaxX, 238};
	TI_RStations[5].TouchFunc = &Menu_RStations_Row6;
}